export default {
  install(Vue) {
    // 数字格式化， 每3位添加一个逗号

    Vue.prototype._formatNum = num => {
      num = (num || 0).toString();
      var result = "";
      while (num.length > 3) {
        result = "," + num.slice(-3) + result;
        num = num.slice(0, num.length - 3);
      }
      if (num) {
        result = num + result;
      }
      return result;
    };

    Vue.prototype._dateTimeFormat = msd => {
      var time = parseFloat(msd) / 1000;
      // 小时
      let h =
        parseInt(time / 3600) < 10 ?
        "0" + parseInt(time / 3600) :
        parseInt(time / 3600);
      // 分钟
      let m =
        parseInt((time / 60) % 60) < 10 ?
        "0" + parseInt((time / 60) % 60) :
        parseInt((time / 60) % 60);
      // 秒
      let s =
        parseInt(time % 60) < 10 ?
        "0" + parseInt(time % 60) :
        parseInt(time % 60);
      return h + ":" + m + ":" + s;
    };

    Vue.prototype._dateFormat = () => {
      let date = new Date();

      let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return hour + ":" + minutes + ":" + seconds;
    };

		Vue.prototype._dateFormat = (msd, needSecond) => {
			let date = new Date(msd == undefined ? '' : msd)
			let month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
			let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
			let hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
			let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
			let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
			if (needSecond) {
				return date.getFullYear() + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
			} else{
				return date.getFullYear() + "-" + month + "-" + day + " " + hour + ":" + minutes;
			}
		}

  }
};
